package com.ruoyi.common.utils;

import java.util.HashMap;
import java.util.Map;

public class SmsTianYanUtil {

    private static final String appId = "Jfk0MApneUX2Eu7h";
    private static final String appSecurity = "Jfk0MApneUX2Eu7hIoyCCKXzr5jZg6Ua";

    public  static void send(String templateId ,  String phone, String tag ){
        String timestamp = System.currentTimeMillis() + "";
        String receive = phone;
//        String tag = "短信发送的标签即替换@`code`@的真实值，多个tag变量用竖线 | 分隔 ，如 aaa|bbb|ccc";
        //接口地址
        String url = "https://api.shumaidata.com/sms/send";

        //请下载MD5Utils文件,地址为 https://file.tianyandata.cn/demo/utils/MD5Utils.java
        String sign = MD5Utils.encrypt(appId+"&"+timestamp+"&"+appSecurity);
        System.out.println("sign: "+sign);

        Map<String,String> headers = new HashMap<String,String>();
        headers.put("Content-Type","application/x-www-form-urlencoded");

        Map<String,Object> params = new HashMap<String,Object>();
        params.put("appid",appId);
        params.put("timestamp",timestamp);
        params.put("sign",sign);
        params.put("templateId", templateId);
        params.put("receive", receive);
        params.put("tag", tag);

        //请下载 HttpUtils文件，地址为 https://file.tianyandata.cn/demo/utils/HttpUtils.java
        String result = HttpUtils.postForm(url,headers,params);
        System.out.println(result);
    }

    public static void main(String[] args){
        String timestamp = System.currentTimeMillis() + "";
        String templateId = "MD04278721";
        String receive = "19955514930";
        String tag = "短信发送的标签即替换@`code`@的真实值，多个tag变量用竖线 | 分隔 ，如 aaa|bbb|ccc";
        //接口地址
        String url = "https://api.shumaidata.com/sms/send";

        //请下载MD5Utils文件,地址为 https://file.tianyandata.cn/demo/utils/MD5Utils.java
        String sign = MD5Utils.encrypt(appId+"&"+timestamp+"&"+appSecurity);
        System.out.println("sign: "+sign);

        Map<String,String> headers = new HashMap<String,String>();
        headers.put("Content-Type","application/x-www-form-urlencoded");

        Map<String,Object> params = new HashMap<String,Object>();
        params.put("appid",appId);
        params.put("timestamp",timestamp);
        params.put("sign",sign);
        params.put("templateId", templateId);
        params.put("receive", receive);
        params.put("tag", tag);

        //请下载 HttpUtils文件，地址为 https://file.tianyandata.cn/demo/utils/HttpUtils.java
        String result = HttpUtils.postForm(url,headers,params);
        System.out.println(result);
    }
}
